let requests = require('requests');
let fs = require('fs') //fs模块
let path = require('path') //path模块


const cheerio = require('cheerio')

requests('https://ncov.dxy.cn/ncovh5/view/pneumonia?from=timeline&isappinstalled=0')
    .on('data', function(chunk) {
        let window = {};
        const $ = cheerio.load(chunk) // cheerio 解析html结构
            // cheerio 解析html结构，得到json格式字符串，再用eval转化成省份信息
        eval($("#getAreaStat").html())

        // 得到html里面的getAreaStat对象，转化成josn格式字符串
        var jsons = JSON.stringify(eval($("#getAreaStat").html()))
        fs.writeFile(path.resolve(__dirname, 'data.json'), jsons, () => {
            // 把字符串写入到dada.json里面去
            console.log('保存成功');
        })
    })